// -----------------------------------------------------------------------
// <copyright file="AspNetUsersInRoles.cs" company="VDC-IT" author="LTDUC">
//      Copyright (c) VDC-IT. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace VDC.VONE.ENTITIES
{
    using System;
    using System.Data.SqlClient;
    using AdCom.Utility;
    using VDC.COMMON;
    
    /// <summary>
    /// Class AspNetUsersInRoles
    /// </summary>
    public class AspNetUsersInRoles
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AspNetUsersInRoles" /> class
        /// </summary>
        public AspNetUsersInRoles()
        {
            this.UserId = Guid.Empty;
            this.RoleId = Guid.Empty;
            this.DepartmentId = 0;
        }

        /// <summary>
        /// Gets or sets UserId
        /// </summary>
        public Guid UserId { get; set; }

        /// <summary>
        /// Gets or sets RoleId
        /// </summary>
        public Guid RoleId { get; set; }

        /// <summary>
        /// Gets or sets DepartmentId
        /// </summary>
        public int DepartmentId { get; set; }

        /// <summary>
        /// Gets Department
        /// </summary>
        public Department Department
        {
            get
            {
                try
                {
                    Department department = null;
                    SqlDataReader reader = SqlDataHelper.ExecuteReader(string.Format(Constants.StorepProcedure.VOneDepartmentGetById, this.DepartmentId));

                    while (reader.Read())
                    {
                        department = new Department();

                        if (!reader.IsDBNull(0))
                        {
                            department.DepartmentId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            department.Code = reader.GetString(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            department.Name = reader.GetString(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            department.Parent = reader.GetInt32(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            department.Order = reader.GetInt32(4);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return department;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
    }
}
